Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Update numberOf{Leading,Trailing}Zeros documentation #119

Closed
wants to merge 1 commit into from

Conversation

osa1
Copy link

@osa1 osa1 commented Oct 18, 2023

  • Mention the result when the integer is 0.
  • Clarify that leading = most significant, trailing = least significant.
  • Remove the documentation from the implementation class.

- Mention the result when the integer is 0.
- Clarify that leading = most significant, trailing = least signitifant.
/// Returns the number of leading (most significant) zeros in this integer's
/// two's complement representation.
///
/// For zero, the result is the same as the integer type's bit max. bit
Copy link
Contributor

@lrhn lrhn Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something left over here? "bit max.bit length".

I don't know what a "bit max" is, and it's not defined.

Maybe:

/// For the value zero, the number of leading zeros is the entire
/// number of bits of the type (64 for [Int64], 32 for [Int32]).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also worth adding that

/// Negative numbers have no leading zero bits, their most signfiicant
/// bit is always set.

@@ -125,12 +125,18 @@ abstract class IntX implements Comparable<Object> {
/// value, add one, i.e. use `x.bitLength + 1`.
int get bitLength;

/// Returns the number of high-order zeros in this integer's bit
/// representation.
/// Returns the number of leading (most significant) zeros in this integer's
Copy link
Contributor

@lrhn lrhn Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're touching this, remove the "Returns". It's a getter, so document using a noun phrase.

(Actually, it's not a getter. It definitely should have been. But it's named as one, with a noun phrase name, so it should still be documented the same way.)

int numberOfLeadingZeros();

/// Returns the number of low-order zeros in this integer's bit
/// representation.
/// Returns the number of trailing (least significant) zeros in this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop "Returns" here too.

/// integer's two's complement representation.
///
/// For zero, the result is the same as the integer type's bit max. bit
/// length.
Copy link
Contributor

@lrhn lrhn Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same phrase,

/// For the value zero, the number of leading zeros is the entire
/// number of bits of the type (64 for [Int64], 32 for [Int32]).

And consider adding

/// Odd numbers have no trailing zero bits, their least significant bit
/// is always set.

It's just explanatory, but may help intuition.

Can also add

/// A number `n` is evenly divisible by `pow(2, n.numberOfTrailingZeros())`.

as another intuitional hint, building on the odd one.

Copy link
Contributor

@lrhn lrhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can keep tweaking documentation forever. Take whatever you like.

@mosuem
Copy link
Contributor

mosuem commented Oct 16, 2024

Closing as the dart-lang/fixnum repository is merged into the dart-lang/core monorepo. Please re-open this PR there!

@mosuem mosuem closed this Oct 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants